import 'package:honeypotflutter/net/public_http.dart';
import 'package:honeypotflutter/publicBussine/view/bussine_modal.dart';
import 'package:honeypotflutter/public/public_total.dart';
import '../model/preferences_listModel.dart';

class PreferencesApi {
  /*
  * 获取设置列表
  * */
  static Future<List<PreferencesListModel>> requestList({int page = 1, String? phone, String? progress}) async {
    Map<String, dynamic> param = {"Page": page, "PageSize": 10, "Phone": phone};
    try {
      List list = await MGHttp.get(
        "api/services/app/PhoneBlackList/PersonalGetPageList",
        params: param,
        progress: progress,
      );
      List<PreferencesListModel> modelList = list.map((e) => PreferencesListModel.fromJson(e)).toList();
      return modelList;
    } catch (error) {
      MGModal.totalError(error);
      return Future.error(error);
    }
  }

  /*
  * 删除
  * */
  static Future<bool> delete(int id) async {
    Map<String, dynamic> param = {"id": id};
    try {
      await MGHttp.delete(
        "api/services/app/PhoneBlackList/PersonalDelete",
        params: param,
        progress: "删除中...",
      );
      HLTotal.total("删除成功");
      return true;
    } catch (error) {
      MGModal.totalError(error);
      return Future.error(error);
    }
  }

  /*
  * 添加偏好设置
  * */
  static Future<bool> addPreferences(String phone, String remarks) async {
    Map<String, dynamic> param = {"phone": phone, "remarks": remarks};
    try {
      await MGHttp.post(
        "api/services/app/PhoneBlackList/PersonalCreate",
        params: param,
        progress: "提交中...",
      );
      return true;
    } catch (error) {
      MGModal.totalError(error);
      return Future.error(error);
    }
  }
}
